This was one of my very first projects in school. We were tasked the challenge of making the game Naughts and Crosses, using a text based user interface (the console). This project helped massively in my understanding of subroutines 2D arrays and loops in VB. In fact just simply writing the board to the screen proved to be challenging however when I had done it successfully it looked like this:
Before the game is played, users must enter a name and a symbol. This involved using a low level form of validation, since the user symbols cannot be the same. After that the actual game can be played. The main control of the program lies inside a while loop which basically swaps the player turn until a player has won or nine moves have been played and there is no winner. On their turn, each player can select two numbers from 1-3 which define where they will place their symbol. If the space is taken, they must choose again and if not the array will be updated with that player’s symbol. Before each turn a check for win subroutine is called which will check for three of the same symbol in a row. If there are three in a row, it will return True and the game will be finished.
Once the game was completed, I added some additional features. These features are displayed in a menu at the start and end of the game and require another level of input validation. The first feature was a save and load feature. The save feature would save the game to a textfile:
The program writes the winner’s name and the date of the game to the file, along with a string of information about the game. When the load feature is selected, users will be asked the winner’s name and the date of the game and the game is extracted from the file and displayed to the user in a reversed process. If there was no winner for the game, the first player’s name is saved.
The final feature I added was the option to play against the computer. Here the computer would just select a random space based on what spaces are available and the user could play against it.